﻿using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace RSTAi.Platform.GrpcService.Common
{
    public class ConfigurationHelper
    {
        #region 字段定义

        private static readonly string CONFIGFILELOCK = "CONFIGFILELOCK";
        //private static readonly string Jwt = "Jwt";
        //private static IConfigurationRoot configurationRoot = null;
        private static ConfigurationManager configurationManager = new();

        #endregion

        #region 单例实现

        private static ConfigurationHelper? _instance = null;

        private ConfigurationHelper()
        {
            //configurationManager = new ConfigurationBuilder()
            //        .SetBasePath(Path.Combine(Directory.GetCurrentDirectory()))
            //        .AddJsonFile("appsettings.json", optional: false)
            //        .Build();
        }

        public static ConfigurationHelper Instance
        {
            get
            {
                lock (CONFIGFILELOCK)
                {
                    if (_instance == null)
                    {
                        _instance = new ConfigurationHelper();
                    }
                    return _instance;
                }
            }
        }

        public ConfigurationManager GetConfigurationManager()
        {
            configurationManager = new();
            configurationManager.SetBasePath(Path.Combine(Directory.GetCurrentDirectory())).AddJsonFile("appsettings.json", optional: false);
            return configurationManager;
        }



        #endregion
    }
}
